
str1 = 'spam eggs'  # single quotes
str2 = 'doesn\'t'   # use \' to escape the single quotes
str3 = "doesn't"    # use double quotes instead


str4 = 'C:\some\name'
str5 = r'C:\some\name'  # use raw strings
print(str4)
print(str5)


str6 = """\
Usage: thingy [Options]
    -h                              Display this usage message
    -H hostname                     Hostname to connect to
"""

print(str6)


str7 = 3 * 'un' + 'ium'  # 'unununium'

# Two or more string literals (i.e. the ones enclosed between quotes) next to each other are automatically concatenated.
str8 = 'Pyh' 'thon'


# 数组与切片

a, b = 0, 1
while a < 10:
    print(a)
    a, b = b, a+b


if a < 10:
    print("if")
elif a == 12:
    print("elif")
else:
    print("else")


words = ['cat', 'window', 'defensetrate']
for w in words:
    print(w,  len(w))


users = {'Hans': 'active', 'Éléonore': 'inactive', '景太郎': 'active'}
# Strategy:  Iterate over a copy
for user, status in users.copy().items():
    if status == 'inactive':
        del users[user]

# Strategy:  Create a new collection
active_users = {}
for user, status in users.items():
    if status == 'active':
        active_users[user] = status


# use range and continue

for num in range(2, 10):
    if num % 2 == 0:
        print("Found an even number", num)
        continue
    print("Found an odd number", num)


def http_error(status):
    match status:
        case 400:
            return "Bad request"
        case 404:
            return "Not found"
        case 418:
            return "I'm a teapot"
        case 401| 403 | 404:
            return "Not allowed"
        case _:
            return "Something's wrong with the internet"
